#!/usr/bin/python
'''
/*
 * This computer program is the confidential information and proprietary trade
 * secret of VistaraIT LLC.  Possessions and use of this program must  conform
 * strictly to the license agreement between the user and VistaraIT LLC.,  and
 * receipt or possession does not convey any rights to divulge, reproduce,  or
 * allow others to use this program without specific written authorization  of
 * VistaraIT LLC.
 * 
 * Copyright (c) 2014 VistaraIT, Inc. All rights reserved.
 */
'''

import re

class NoCacheMiddleware(object):

    def process_response(self, request, response):
        iscachable = self.isCachable(request)
        #Should not pass server details this will give some clue for the the hackers to perform some attacks
        response['Server'] = 'App Server'
        if iscachable == False:
            response["Cache-Control"] = "max-age=0, must-revalidate"
        return response
    
    def isCachable(self,request):
        reg_exp = '\\/(css|js|img|images|applet)\\/.*'
        uri = request.get_full_path()
        return re.match(reg_exp,uri) != None
